<jcpsm:pageContainer>
<c:if test="${not empty sessionScope.isUserLoggedIn && empty sessionScope.admin}">
	<jsp:forward page="/profile/home.jsp"></jsp:forward>
</c:if>
<c:if test="${empty sessionScope.isUserLoggedIn && empty sessionScope.admin}">
	<jsp:forward page="/index.jsp"></jsp:forward>
</c:if>
	<div class="content">
	<div class="">
	<h1 class="title">Manage <span>Tracks</span></h1>
	<c:if test="${not empty sessionScope.track}">
	<table class="gridtable" width="100%" border="1" style="box-shadow: 5px 5px 8px #888888;">
		<tr align="center" class="fillgray">
			<td class="heading fillgray">
				Name
			</td>
			<td class="heading fillgray">
				Code
			</td>
			<td class="heading fillgray">
				Description
			</td>
			<td class="heading fillgray">
				Owner
			</td>
			<td width="5%" class="fillgray">
				&nbsp;
			</td>
			<td width="5%" class="fillgray">
				&nbsp;
			</td>
		</tr>
		
		<c:forEach var="trackEntry" items="${sessionScope.track}">
		<c:if test="${trackEntry.value.deleteFlag == false}">
 	 		<tr align="center">
			<td class="heading">
				${trackEntry.value.name}
			</td>
			<td class="heading">
				${trackEntry.value.code}
			</td>
			<td class="heading">
				${trackEntry.value.description}
			</td>
			<td class="heading">
				${sessionScope.approvedUsers[trackEntry.value.owner].name} 
			</td>
			<td width="5%">
				<a href="${contextRoot}/editTrack?trackId=${trackEntry.value.trackId}"><img src="${mediaRoot}/edit_icon.gif"/></a>
			</td>
			<td width="5%">
				<a href="${contextRoot}/deleteTrack?trackId=${trackEntry.value.trackId}"><img src="${mediaRoot}/delete_icon.gif"/></a>
			</td>
		</tr>
 	 			</c:if>
		</c:forEach>
	</table>
	</c:if>
	
<c:if test="${not empty sessionScope.editTrackInfo}">
<s:form action="updateTrack">
	<table border="0" class="track_table" align="center" style="margin-left: 280px;">
		<input name="trackId" type="hidden" value="${sessionScope.editTrackInfo.trackId}"/>
		<tr><td>Track Name</td><td>
				<s:textfield name="name"  theme="simple" cssClass="syle_input width_200" value="%{#session.editTrackInfo.name}"/>
			</td></tr><tr>
			<td>Track Code</td><td><s:textfield name="code" theme="simple" cssClass="syle_input width_200" value="%{#session.editTrackInfo.code}"/>
			</td></tr><tr>
			<td>Description</td><td><s:textarea name="description" theme="simple" cssClass="syle_input width_200" value="%{#session.editTrackInfo.description}"/>
			</td></tr><tr><td>Owner</td><td>
				<select id="owner_display" name="owner" class="syle_input width_222">
					<c:forEach var="userEntry" items="${sessionScope.approvedUsers}">
						<c:if test="${sessionScope.editTrackInfo.owner eq userEntry.value.id}">
							<option value="${userEntry.value.id}" selected="selected">${userEntry.value.name}</option>
						</c:if>
						<c:if test="${sessionScope.editTrackInfo.owner ne userEntry.value.id}">
							<option value="${userEntry.value.id}">${userEntry.value.name}</option>
						</c:if>
					</c:forEach>
				</select>
			</td></tr><tr><td>
				
			</td>
			<td>
			<a href="${contextRoot}/cancelTrackEdit">Cancel</a>
				<s:submit cssClass="stylebutton mrgrgt80 mrgtp5" value="Update" theme="simple" cssStyle="float:right;"/>
			</td></tr>
	</table>
</s:form>
</c:if>
<c:if test="${empty sessionScope.editTrackInfo}">
<s:form action="addTrack">
	<table border="0" class="track_table" align="center" style="margin-left: 280px;" >
		<tr><td>Track Name</td><td>
				<s:textfield name="name"  theme="simple" cssClass="syle_input width_200" />
			</td></tr><tr>
			<td>Track Code</td><td><s:textfield name="code" theme="simple" cssClass="syle_input width_200"/>
			</td></tr><tr>
			<td>Description</td><td><s:textarea name="description" theme="simple" cssClass="syle_input width_200"/>
			</td></tr><tr><td>Owner</td><td>
				<select id="owner_display" name="owner" class="syle_input width_222">
					<option value="-1">select</option>
					<c:forEach var="userEntry" items="${sessionScope.approvedUsers}">
						<option value="${userEntry.value.id}">${userEntry.value.name}</option>
					</c:forEach>
				</select>
			</td></tr><tr><td colspan="2"><s:submit cssClass="stylebutton mrgrgt80 mrgtp5" value="Create" theme="simple" cssStyle="float:right;"/>
			</td></tr>
	</table>
</s:form>
</c:if>

	</div>
	</div>
</jcpsm:pageContainer>